package com.ksd.control;

import com.alibaba.fastjson.JSONObject;
import com.ksd.control.result.BaseResult;
import com.ksd.control.result.ResultParam;
import com.ksd.dao.INoticeDAO;
import com.ksd.pojo.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller()
public class NoticeAction extends BaseAction implements CRUB {
    @Autowired
    private INoticeDAO noticeDAO;

    private List noticeList;
    private String update;
    private String delete;
    private String insert;

    public List getNoticeList() {
        return noticeList;
    }

    public void setNoticeList(List noticeList) {
        this.noticeList = noticeList;
    }

    public String getUpdate() {
        return update;
    }

    public void setUpdate(String update) {
        this.update = update;
    }

    public String getDelete() {
        return delete;
    }

    public void setDelete(String delete) {
        this.delete = delete;
    }

    public String getInsert() {
        return insert;
    }

    public void setInsert(String insert) {
        this.insert = insert;
    }

    @Override
    public String list() {
        noticeList = noticeDAO.findAll();
        setResult(new BaseResult().setResult(ResultParam.SUCCESS));
        return SUCCESS;
    }

    @Override
    public String update() {
        Notice notice = JSONObject.parseObject(update, Notice.class);
        noticeDAO.update(notice);
        return SUCCESS;
    }

    @Override
    public String delete() {
        Notice notice = JSONObject.parseObject(delete, Notice.class);
        noticeDAO.delete(String.valueOf(notice.getId()));
        return SUCCESS;
    }

    @Override
    public String insert() {
        Notice notice = JSONObject.parseObject(insert, Notice.class);
        noticeDAO.insert(notice);
        return SUCCESS;
    }
}
